package com.simple.database.controller;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.propertyeditors.PropertiesEditor;

public class MyCustomDateEditor extends PropertiesEditor {

	@Override
	public void setAsText(String text) throws IllegalArgumentException {
		Date date =null;
		if(StringUtils.isNotBlank(text)){
			try {
				date = new SimpleDateFormat("yyyy-MM-dd-HH:mm:ss").parse(text);
			} catch (ParseException e) {
				e.printStackTrace();
			}
		}else{
			text = "";
		}
		setAsText(new SimpleDateFormat("yyyy-MM-dd-HH:mm:ss").format(date));
	}
	
	@Override
	public String getAsText() {
		System.out.println(getValue().toString());
		return getValue().toString();
	}
}
